﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace Max.PH5_2008A.ShoppingCode.EFCoreDbFirst.Models;

public partial class Ph52008aShoppingContext : DbContext
{
    public Ph52008aShoppingContext()
    {
    }

    public Ph52008aShoppingContext(DbContextOptions<Ph52008aShoppingContext> options)
        : base(options)
    {
    }

    public virtual DbSet<TbBaseCity> TbBaseCities { get; set; }

    public virtual DbSet<TbCategorySpec> TbCategorySpecs { get; set; }

    public virtual DbSet<TbCategorySpecValue> TbCategorySpecValues { get; set; }

    public virtual DbSet<TbMemeberInfo> TbMemeberInfos { get; set; }

    public virtual DbSet<TbProductBrand> TbProductBrands { get; set; }

    public virtual DbSet<TbProductCategory> TbProductCategories { get; set; }

    public virtual DbSet<TbProductSku> TbProductSkus { get; set; }

    public virtual DbSet<TbProductSpu> TbProductSpus { get; set; }

    public virtual DbSet<TbProductSpuSpecValue> TbProductSpuSpecValues { get; set; }

    public virtual DbSet<TbSystemLog> TbSystemLogs { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("server=.;database=PH52008A_Shopping;uid=sa;pwd=qwe123;TrustServerCertificate=true;");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<TbBaseCity>(entity =>
        {
            entity.ToTable("tb_base_city");

            entity.Property(e => e.Id).ValueGeneratedNever();
            entity.Property(e => e.Pid).HasColumnName("PId");
        });

        modelBuilder.Entity<TbCategorySpec>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_TB_CATEGORY_SPEC");

            entity.ToTable("tb_Category_Spec", tb => tb.HasComment("商品模块 - 商品的规格定义"));

            entity.Property(e => e.Id)
                .HasDefaultValueSql("(newid())")
                .HasComment("主键");
            entity.Property(e => e.CategoryId).HasComment("分类Id ");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("规格名称");

            entity.HasOne(d => d.IdNavigation).WithOne(p => p.TbCategorySpec)
                .HasForeignKey<TbCategorySpec>(d => d.Id)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_TB_CATEG_REFERENCE_TB_CATEG");
        });

        modelBuilder.Entity<TbCategorySpecValue>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_TB_CATEGORY_SPEC_VALUE");

            entity.ToTable("tb_Category_Spec_Value", tb => tb.HasComment("商品模块 - 商品规格对应值"));

            entity.Property(e => e.Id).HasDefaultValueSql("(newid())");
            entity.Property(e => e.SpecId).HasComment("规格Id");
            entity.Property(e => e.Value)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("规格值");
        });

        modelBuilder.Entity<TbMemeberInfo>(entity =>
        {
            entity.ToTable("tb_memeber_info");

            entity.Property(e => e.Id).ValueGeneratedNever();
        });

        modelBuilder.Entity<TbProductBrand>(entity =>
        {
            entity
                .HasNoKey()
                .ToTable("tb_Product_Brand", tb => tb.HasComment("商品模块 - 商品品牌"));

            entity.Property(e => e.Description)
                .HasMaxLength(500)
                .IsUnicode(false)
                .HasComment("品牌描述");
            entity.Property(e => e.Id)
                .HasDefaultValueSql("(newid())")
                .HasComment("品牌主键");
            entity.Property(e => e.Logo)
                .HasMaxLength(200)
                .IsUnicode(false)
                .HasComment("品牌Logo");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("品牌名称");
        });

        modelBuilder.Entity<TbProductCategory>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_TB_PRODUCT_CATEGORY");

            entity.ToTable("tb_Product_Category", tb => tb.HasComment("商品模块 - 商品分类"));

            entity.Property(e => e.Id)
                .HasDefaultValueSql("(newid())")
                .HasComment("分类主键");
            entity.Property(e => e.Icon)
                .HasMaxLength(200)
                .IsUnicode(false)
                .HasComment("分类对应的图标");
            entity.Property(e => e.Level).HasComment("分类的级别");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("分类的名称");
            entity.Property(e => e.Pid)
                .HasComment("父ID")
                .HasColumnName("PId");
        });

        modelBuilder.Entity<TbProductSku>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_TB_PRODUCT_SKU");

            entity.ToTable("tb_Product_SKU", tb => tb.HasComment("商品模块 - 商品SKU表"));

            entity.Property(e => e.Id)
                .HasDefaultValueSql("(newid())")
                .HasComment("商品SKU主键");
            entity.Property(e => e.Code)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("商品编码");
            entity.Property(e => e.CreatedBy)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.CreatedTime)
                .HasComment("创建日期")
                .HasColumnType("datetime");
            entity.Property(e => e.Flag)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("标识");
            entity.Property(e => e.IsUp)
                .HasMaxLength(2)
                .IsUnicode(false)
                .HasComment("是否上架");
            entity.Property(e => e.LockStock).HasComment("锁定库存");
            entity.Property(e => e.MarketPrice)
                .HasComment("市场价格")
                .HasColumnType("decimal(18, 0)");
            entity.Property(e => e.MinStock).HasComment("最少库存");
            entity.Property(e => e.PurchasePrice)
                .HasComment("采购价格")
                .HasColumnType("decimal(18, 0)");
            entity.Property(e => e.SaleNumber).HasComment("销售数量");
            entity.Property(e => e.SalePrice)
                .HasComment("销售价格")
                .HasColumnType("decimal(18, 0)");
            entity.Property(e => e.Spuid)
                .HasComment("SPUId")
                .HasColumnName("SPUId");
            entity.Property(e => e.Stock).HasComment("原始库存");
            entity.Property(e => e.UpdateBy)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");
            entity.Property(e => e.ValidStock).HasComment("有效库存（可用）");
        });

        modelBuilder.Entity<TbProductSpu>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_TB_PRODUCT_SPU");

            entity.ToTable("tb_Product_SPU", tb => tb.HasComment("商品模块 - 商品SPU表"));

            entity.Property(e => e.Id)
                .HasDefaultValueSql("(newid())")
                .HasComment("SPU主键");
            entity.Property(e => e.BrandId).HasComment("品牌ID");
            entity.Property(e => e.CategoryId).HasComment("分类Id");
            entity.Property(e => e.Code)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("产品编码");
            entity.Property(e => e.CreatedBy)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("创建人");
            entity.Property(e => e.CreatedTime)
                .HasComment("创建日期")
                .HasColumnType("datetime");
            entity.Property(e => e.Description)
                .HasComment("产品描述")
                .HasColumnType("text");
            entity.Property(e => e.MasterImage)
                .HasMaxLength(200)
                .IsUnicode(false)
                .HasComment("主图");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasComment("产品名称");
            entity.Property(e => e.UpdateBy)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("更新人");
            entity.Property(e => e.UpdateTime)
                .HasComment("更新时间")
                .HasColumnType("datetime");
        });

        modelBuilder.Entity<TbProductSpuSpecValue>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_TB_PRODUCT_SPU_SPEC_VALUE");

            entity.ToTable("tb_Product_SPU_Spec_Value", tb => tb.HasComment("商品模块 - 商品SKU规格值表"));

            entity.Property(e => e.Id)
                .HasDefaultValueSql("(newid())")
                .HasColumnName("ID");
            entity.Property(e => e.Skuid).HasColumnName("SKUId");
            entity.Property(e => e.SpecId).HasComment("规格ID");
            entity.Property(e => e.SpecValueId).HasComment("规格值ID");
        });

        modelBuilder.Entity<TbSystemLog>(entity =>
        {
            entity.ToTable("tb_system_log");

            entity.Property(e => e.Id).ValueGeneratedNever();
            entity.Property(e => e.Ip).HasColumnName("IP");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
